package st.business.tepth.business.visitor.visitorwork.work.detail;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;

import butterknife.BindView;
import st.business.tepth.R;
import st.business.tepth.R2;
import st.business.tepth.business.visitor.visitorwork.entity.WorkDetailBean;
import st.shadow.library.core.base.fragment.BaseFragment;

/**
 * @author zhangyu
 * @date 2019/6/5
 */
public class RepairDelegate extends BaseFragment {
    public static RepairDelegate newInstance(ArrayList<WorkDetailBean.RepairBean> list) {
        Bundle bundle = new Bundle();
        bundle.putParcelableArrayList("list", list);
        RepairDelegate delegate = new RepairDelegate();
        delegate.setArguments(bundle);
        return delegate;
    }

    @BindView(R2.id.recycler_view)
    RecyclerView mRecyclerView;
    private RepairAdapter mRepairAdapter;
    private ArrayList<WorkDetailBean.RepairBean> mRepairBeans;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle bundle = getArguments();
        if (bundle != null) {
            mRepairBeans = bundle.getParcelableArrayList("list");
        }
    }

    @Override
    public Object setLayout() {
        return R.layout.delegate_work_read_only_detail_repair;
    }

    @Override
    public void onBindView(@Nullable Bundle savedInstanceState, View rootView) {
        mRecyclerView.setLayoutManager(new LinearLayoutManager(_mActivity));
        mRepairAdapter = new RepairAdapter(new DataConvert()
                .convertRepair(mRepairBeans));
        mRecyclerView.setAdapter(mRepairAdapter);
        mRepairAdapter.setEmptyView(R.layout.view_search_empty,
                (ViewGroup) mRecyclerView.getParent());
    }

    public void resetData(ArrayList<WorkDetailBean.RepairBean> repairBeans) {
        if (mRepairAdapter != null) {
            mRepairAdapter.setNewData(new DataConvert()
                    .convertRepair(repairBeans));
        }
    }
}
